<template>
  <el-row :gutter="20">
    <el-col :span="12" :xs="24">
      <AppSiteSimpleList @row-click="handleAppSiteSimpleListRowClick" />
    </el-col>
    <el-col :span="12" :xs="24">
      <div class="head-container">
        <!-- 搜索工作栏 -->
        <el-input
          v-model="queryParams.albumName"
          placeholder="请输入相册名称"
          clearable
          @keyup.enter="handleQuery"
          class="mb-20px"
        />
      </div>

      <!-- 列表 -->
      <div class="head-container">
        <el-table
          v-loading="loading"
          :data="list"
          :stripe="true"
          :show-overflow-tooltip="true"
          @row-click="handleRowClick"
          highlight-current-row
        >
          <el-table-column label="相册名称" align="center" prop="albumName" />
        </el-table>
        <!-- 分页 -->
        <Pagination
          :total="total"
          v-model:page="queryParams.pageNo"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
          layout="total, prev, next"
        />
      </div>
    </el-col>
  </el-row>
</template>

<script setup lang="ts">
import { AppSiteAlbumApi, AppSiteAlbumVO } from '@/api/cms/appsitealbum'
import AppSiteSimpleList from '@/views/cms/appsite/AppSiteSimpleList.vue'
import { AppSiteVO } from '@/api/cms/appsite'

/** 站点相册 列表 */
defineOptions({ name: 'AppSiteAlbumSimpleList' })

const loading = ref(true) // 列表的加载中
const list = ref<AppSiteAlbumVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  appSiteId: 0,
  appId: '',
  albumName: undefined,
  status: undefined,
  createTime: []
})
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await AppSiteAlbumApi.getAppSiteAlbumPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 处理某一行的点击 */
const handleRowClick = (row: AppSiteAlbumVO) => {
  emits('row-click', row)
}
const emits = defineEmits(['row-click'])

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}
const currAppSiteVO = ref<AppSiteVO>()
const handleAppSiteSimpleListRowClick = (row: AppSiteVO) => {
  queryParams.appSiteId = row.id
  queryParams.appId = row.appId
  currAppSiteVO.value = row
  handleQuery()
  handleRowClick({
    appSiteId: row.id,
    appId: row.appId
  } as AppSiteAlbumVO)
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
